local logger = require "resty.logger.socket"
local cjson = require "cjson"

if not logger.initted() then
  local ok, err = logger.init {
      host = "47.98.215.159", --部署时,需要填写logserver服务器ip
      port = 514,--部署时,需要填写logserver服务器port
      sock_type = "tcp",--采用udp传输
      flush_limit = 1,--1就是时实传输,
      --drop_limit = 5678, --默认1mb 超过会自动删除
      timeout = 10000,--超时设置
      pool_size = 100 --连接池大小
  }
  if not ok then
      ngx.log(ngx.ERR, "failed to initialize the logger: ", err)
      return
  end
end

client_ip = ngx.var.remote_addr
local args = ngx.req.get_post_args(10)
if not args then
    ngx.say("failed to get post args")
    return 
end
-- ngx.req.read_body()

logstr = cjson.encode(args).."\n"

local bytes, err = logger.log(logstr)
if err then
    ngx.log(ngx.ERR, "failed to log message: ", err)
    return
end